package hanjia;

import java.util.LinkedList;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/11-下午4:24
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode513 {

    public int findBottomLeftValue(TreeNode root) {

        if (root.left == null && root.right == null) {
            return root.val;
        }

        LinkedList<TreeNode> queue = new LinkedList<>();
        queue.offer(root);
        int result=0;
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {

                TreeNode poll = queue.poll();
                if (i==0){
                    result=poll.val;
                }
                if (poll.left != null) {
                    queue.add(poll.left);
                }
                if (poll.right!=null){
                    queue.add(poll.right);
                }

            }


        }
        return result;


    }
}
